<?php
/**
 * Created by jinqiang on 2025/4/24 13:50.
 * Copyright (c) 2025, Your Company. All rights reserved.
 */


namespace App\Http\Controllers\Om;


use App\Http\Controllers\Controller;
use App\Http\Models\Mysql\SsyJyProductListTable;
use App\Http\Services\Om\ExportService;
use Illuminate\Http\Request;

class ExportController extends Controller
{
    public function list(Request $request, ExportService $exportService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $exportService->search($param);
        return result($res);
    }

    //搜索运营订单款号数量
    public function search(Request $request, ExportService $exportService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $exportService->searchCount($param);
        return result($res);
    }

    //锁定、解锁
    public function lock(Request $request, ExportService $exportService)
    {
        $this->validate($request, [
            'id' => 'required',
            'state' => 'required|in:0,1'
        ]);
        $param = $request->all();
        $res = $exportService->lock((Int)$param['id'], (Int)$param['state']);
        return $res['code'] === 0 ? success($param['state'] == 1 ? "锁定成功" : "解锁成功") : error($res['msg'], $res);
    }

    //删除
    public function del(Request $request, ExportService $exportService)
    {
        $this->validate($request, [
            'id' => 'required'
        ]);
        $param = $request->all();
        $res = $exportService->del((Int)$param['id']);
        return $res['code'] === 0 ? success("删除成功") : error($res['msg'], $res);
    }

    //详情
    public function detail(Request $request, ExportService $exportService)
    {
        $this->validate($request, [
            'id' => 'required'
        ]);
        $param = $request->all();
        $res = $exportService->detail((Int)$param['id']);
        return result($res);
    }

    //选择款式颜色
    public function styleList(Request $request, ExportService $exportService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $exportService->searchStyle($param);
        return result($res);
    }

    //保存
    public function save(Request $request, ExportService $exportService)
    {
        $this->validate($request, [
            'export_order' => 'required',
            'detail_list' => 'required',
            'size_list' => 'required'
        ]);
        $param = $request->all();
        $res = $exportService->save($param);
        return $res['code'] === 0 ? success("保存成功") : error($res['msg'], $res);
    }
}
